﻿#region MIT Licenze
//The MIT License

//Copyright (c) 2008 Sebastian Faltoni, dotnetfireball.org

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.ComponentModel;

namespace Fireball.OpenXML.Word
{
    public class ParagraphProperties : IOpenXMLEntity
    {
        /*//<adjustRightInd 
        /// <summary>
        /// Adjust right ident when
        /// using Document Grid
        /// </summary>
        public bool AdjustRightIndent
        {
            get;
            set;
        }*/

        /// <summary>
        /// Specify the indentation for this paragraph
        /// </summary>
        public ParagraphIndentation Indent
        {
            get;
            set;
        }

        /// <summary>
        /// The Style associated with this paragraph
        /// </summary>
        public string Style
        {
            get;
            set;
        }

        /// <summary>
        /// Specify to show the paragraph as a numbered list 
        /// or bullet list (this depend on a style)
        /// </summary>
        public bool IsList { get; set; }

        
        /// <summary>
        /// Paragraph Conditional Formatting Style
        /// If this value is specified other's will be ignored
        /// </summary>
        public decimal? ConditionalFormattingStyle
        {
            get;
            set;
        }

        /// <summary>
        /// Ignore spaces above and below when using identical styles
        /// </summary>
        public bool? ContextualSpacing
        {
            get;
            set;
        }

        /// <summary>
        /// The HtmlDiv ID  for this paragraph
        /// </summary>
        public string HtmlDivId
        {
            get;
            set;
        }


        /// <summary>
        /// Specify the alignment for this paragraph
        /// </summary>
        [DefaultValue(ParagraphAlignment.None)]
        public ParagraphAlignment Alignment
        {
            get;
            set;
        }

        //decimal value
        /// <summary>
        /// Associated outline level
        /// </summary>
        public decimal? AssociatedOutlineLevel
        {
            get;
            set;
        }

        /// <summary>
        /// The styles properties for this paragraph
        /// </summary>
        public StyleRunProperties RunProperties
        {
            get;
            set;
        }

        public ParagraphSpacing Spacing
        {
            get;
            set;
        }

        #region IOpenXMLEntity Members

        public string Name
        {
            get;
            set;
        }

        public XContainer ToXml()
        {
            XElement xProp = new XElement(NS.WM + "pPr");

            if (!string.IsNullOrEmpty(this.Style))
            {
                xProp.Add(
                    new XElement(NS.WM + "pStyle",
                        new XAttribute(NS.WM + "val", this.Style)));
            }
            if (this.IsList)
            {
                xProp.Add(
                    new XElement(NS.WM + "numPr",
                        new XElement(NS.WM + "ilvl",
                            new XAttribute(NS.WM + "val", 0)),
                        new XElement(NS.WM + "numId",
                            new XAttribute(NS.WM + "val", 1))));
            }

            if (this.Indent != null)
                xProp.Add(this.Indent.ToXml());

            if (this.ContextualSpacing != null)
                xProp.Add(new XElement(NS.WM + "contextualSpacing",
                    new XAttribute(NS.WM + "val",
                    this.ContextualSpacing.Value.ToOnOff())));


            if (this.Spacing != null)
            {
                xProp.Add(this.Spacing.ToXml());
            }

            if (this.Alignment != ParagraphAlignment.None)
                xProp.Add(new XElement(NS.WM + "jc",
                    new XAttribute(NS.WM + "val", this.Alignment.ToOffice())));

            if (this.AssociatedOutlineLevel != null)
            {
                xProp.Add(new XElement(NS.WM + "outlineLvl",
                    new XAttribute(NS.WM + "val", this.AssociatedOutlineLevel.Value)));
            }

            if (this.ConditionalFormattingStyle != null)
                xProp.Add(new XElement(NS.WM + "cnfStyle",
                    new XAttribute(NS.WM + "val", this.ConditionalFormattingStyle.Value)));

            if (this.RunProperties != null)
                xProp.Add(this.RunProperties.ToXml());



           

            return xProp;
        }

        #endregion

        internal static ParagraphProperties Parse(XElement pPr)
        {
            throw new NotImplementedException();
        }
    }
}
